﻿////////////////////////////////////////////////////////////////
///
/// File: BodyContent.cs
/// Author: Lucio Davide Spano
/// Last update: 27 July 2012
/// Description: Delegate that defines the behaviour of a ground 
///              term for the multitouch platform
/// To do: 
/// ------------------------------------------------------------
/// Copyright (c) 2012 Lucio Davide Spano 
///                     (lucio.davide.spano@isti.cnr.it)
/// 
/// The use and distribution terms for this software are 
/// contained in the file named license.txt, which can be found 
/// in the root of this distribution.
/// By using this software in any fashion, you are agreeing to 
/// be bound by the terms of this license.
///
/// You must not remove this notice, or any other, from this
/// software.
/// ------------------------------------------------------------
////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using GestIT;
namespace TouchGestIT
{

    public class TouchContent : ExpContent
    {
        public TouchType Type { get; set; }
        public int Id { get; set; }

        public TouchContent()
            : base()
        {
            
        }

        public TouchContent(TouchType type, int id)
            : base()
        {
            this.Type = type;
            this.Id = id;
        }

        public override bool Accepts(ExpEventArgs args, Token token)
        {
            if (!(args is TouchEventArgs))
            {
                return false;
            }
            TouchEventArgs targs = (TouchEventArgs)args;

            if (targs.Id != this.Id)
            {
                return false;
            }

            if (targs.Type != this.Type)
            {
                return false;
            }

            return true;
        }   

        public override bool Consume(ExpEventArgs args, Token token)
        {
            if (!(args is TouchEventArgs) || !(token is TouchToken))
            {
                return false;
            }
            TouchEventArgs targs = (TouchEventArgs)args;
            TouchToken tToken = (TouchToken)token;
            tToken.Save(targs);
            return true;
        }
    }

    public enum TouchType
    {
        Start, Move, End
    }
}
